package com.example.day09;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.viewpager.widget.ViewPager;

import com.example.day09.fragment.AFragment;
import com.example.day09.fragment.ErkFragment;
import com.example.day09.fragment.RecyFragment;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private Toolbar mToob;
    private ViewPager mVp;
    private TabLayout mTab;
    private FragmentManager manager;
    private ArrayList<Fragment> fragments;
    private Vp_Frag vp_frag;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        mToob = (Toolbar) findViewById(R.id.toob);
        mVp = (ViewPager) findViewById(R.id.vp);
        mTab = (TabLayout) findViewById(R.id.tab);

        mToob.setTitle("");
        setSupportActionBar(mToob);

        manager = getSupportFragmentManager();
        fragments = new ArrayList<>();
        fragments.add(new AFragment());
        fragments.add(new RecyFragment());
        fragments.add(new ErkFragment());
        vp_frag = new Vp_Frag(manager, fragments);
        mVp.setAdapter(vp_frag);
        mTab.setupWithViewPager(mVp);

        mTab.getTabAt(0).setText("首页");
        mTab.getTabAt(1).setText("多布局");
        mTab.getTabAt(2).setText("二级列表");


    }
}
